

Object::Object() {
	this->cor = new Color(255, 255, 255);
	this->posicao = new Vector(0 , 0, 0);
	this->kAmbiente = 0;
	this->kDifusa = 1;
	this->kEspecular = 0.2;
	this->nShing = 1;
	this->orientacao = Matrix3D::getIdentidade();
}

Object::Object(Color *cor,Vector *posicao,double kAmbiente,double kDifusa, double kEspecular,int nShing) {
	this->cor = cor;
	this->kAmbiente = kAmbiente;
	this->posicao = posicao,
	this->kDifusa = kDifusa;
	this->kEspecular = kEspecular;
	this->nShing = nShing;
	this->orientacao = Matrix3D::getIdentidade();
	
}

Object::~Object() {
	if (this->posicao) delete this->posicao;
	if (this->cor) delete this->cor;
}


Vector* Object::getPosicao(){
	return this->posicao;
}

void Object::setPosicao(Vector *p){
	delete this->posicao;
	this->posicao = p;
}

bool Object::testarColisao(Ray *raio) {
	return true;
}

Vector* Object::vetorNormal(Ray *raio) {
	return NULL;
}

Intersect* Object::intersecsao(Ray *raio){
	
	return NULL;
}

void Object::rotacionar(double x, double y, double z) {
	double mrx[3][3],mry[3][3],mrz[3][3];
	//matriz de rotacao x
	mrx[0][0] = 1;
	mrx[0][1] = mrx[0][2] = mrx[1][0] = mrx[2][0] = 0;
	mrx[1][1] = mrx[2][2] = cos(DEG2RAD(x));
	mrx[2][1] = sin(DEG2RAD(x));
	mrx[1][2] = - mrx[2][1];
	
	//matriz de rotacao y
	mry[1][1] = 1;
	mry[0][1] = mry[1][0] = mry[1][2] = mry[2][1] = 0;
	mry[0][0] = mry[2][2] = cos(DEG2RAD(y));
	mry[0][2] = sin(DEG2RAD(y));
	mry[2][0] = - mry[0][2];
	
	//matriz de rotacao z
	mrz[2][2] = 1;
	mrz[0][2] = mrz[1][2] = mrz[2][0] = mrz[2][1] = 0;
	mrz[0][0] = mrz[1][1] = cos(DEG2RAD(z));
	mrz[1][0] = sin(DEG2RAD(z));
	mrz[0][1] = - mrz[1][0];
	
	Matrix3D *rtX = new Matrix3D(mrx);
	Matrix3D *rtY = new Matrix3D(mry);
	Matrix3D *rtZ = new Matrix3D(mrz);
	
	Matrix3D *pt1,*pt2;
	//realiza a multiplicacao da orientacao atual por x
	pt1 = this->orientacao->multiplicacao(rtX);
	//realiza a multiplicacao por y
	pt2 = pt1->multiplicacao(rtY);
	delete pt1;
	//realiza a multiplicacao por z
	pt1 = pt2->multiplicacao(rtZ);
	delete this->orientacao;
	//armazena o resultado
	this->orientacao = pt1;
}

void Object::deslocar(double x, double y, double z) {
	if (this->posicao) {
		Vector *t = new Vector(x,y,z);
		Vector *n = this->posicao->soma(t);
		delete t;
		delete this->posicao;
		this->posicao = n;
	}
}
